﻿@{
    ViewData["Title"] = "车辆到位管理";
}
<div class="box2" panelTitle="检索条件">
    <form id="queryForm" method="post">
        <table formMode="transparent">
            <tr>
                <td>供应商编号：</td>
                <td><input type="text" name="warehouseName" id="warehouseName" /></td>
                <td>供应商名称：</td>
                <td><input type="text" name="warehouseDesc" id="warehouseDesc" /></td>
                <td>是否启用：</td>
                <td>
                    <select name="enabled" selectedValue="Y" data='{"list":[{"value":"","key":"全部"},{"value":"Y","key":"是"},{"value":"N","key":"否"}]}'></select>
                </td>
                <td><button type="button" onclick="searchHandler()"><span class="icon_find">查询</span></button></td>
                <td><button type="button" onclick="resetSearch()"><span class="icon_reload">重置</span></button></td>
            </tr>
        </table>
    </form>
</div>

<div>
    <div class="padding_right5">
        <div id="maingrid"></div>
    </div>
</div>

<script type="text/javascript">
    var grid;
    function initComplete() {
        grid = $("#maingrid").quiGrid({
            columns: [
                { display: '供应商编号', name: 'supplierCode', align: 'left', width: "7%" },
                { display: '供应商名称', name: 'supplierName', align: 'left', width: "7%" },
                { display: '计划到达时间', name: 'planArriveTime', align: 'left', width: "7%" },
                { display: '实际到达时间', name: 'realArriveTime', align: 'left', width: "7%" },
                { display: '送达状态', name: 'arriveType', align: 'left', width: "7%" },
                { display: '厂内装卸状态', name: 'carInPlantType', align: 'left', width: "7%" },
                { display: '道口', name: 'passageway', align: 'left', width: "7%" },
                { display: '实际进厂时间', name: 'realInPlantTime', align: 'left', width: "7%" },
                { display: '开始卸货时间', name: 'startWorkTime', align: 'left', width: "7%" },
                { display: '是否打印发行单', name: 'isPrintOutPlantList', align: 'left', width: "7%" },
                { display: '开据发行单时间', name: 'printOutPlantListTime', align: 'left', width: "7%" },
                { display: '出厂时间', name: 'outPlantTime', align: 'left', width: "7%" },
                { display: '启用/禁用', name: 'enabled', align: 'left', width: "10%" }
            ],
            url: '/CarManager/CarManager/getWarehouseListByPage', sortName: 'planArriveTime', rownumbers: true, checkbox: true,
            height: '100%', width: "100%", percentWidthMode: true, pageSize: 20,
            //顶部图标按钮栏
            toolbar: {}
        });
        //载入工具栏图标
        loadToolbar("", grid);
    }

    //查询
    function searchHandler() {
        //得到查询参数
        var query = $("#queryForm").formToArray();
        //将查询参数传给grid表格
        grid.setOptions({ params: query });
        //页号重置为1
        grid.setNewPage(1);
        //重新加载数据
        grid.loadData();
    }

    //重置查询
    function resetSearch() {
        $("#queryForm")[0].reset();
        searchHandler();
    }

    //添加
    function onAdd() {
        top.Dialog.open({ URL: "/WarehouseDefine/editWarehouse", Title: "新增", Width: 500, Height: 250 });
    }


    //删除后的提示
    function handleResult(result) {
        if (result != -1) {
            top.Dialog.alert("删除成功！删除" + result + "条数据", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("删除失败！");
        }
    }


    //获取所有选中行获取选中行的id 格式为 ids=1&ids=2
    function getSelectId(grid) {
        var selectedRows = grid.getSelectedRows();
        var selectedRowsLength = selectedRows.length;
        var ids = "";

        for (var i = 0; i < selectedRowsLength; i++) {
            ids += selectedRows[i].warehouseId + ",";
        }
        return { "ids": ids };
    }


    //修改
    function onEdit() {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选中要编辑的记录!");
            return;
        } else if (rowsLength > 1) {
            top.Dialog.alert("只能选择一行编辑");
            return;
        }
        top.Dialog.open({
            URL: "/WarehouseDefine/editWarehouse?warehouseId=" + rows[0].warehouseId,
            Title: "修改", Width: 500, Height: 250
        });
    }

    //启用
    function EnablehandleResult(result) {
        if (result != -1) {
            top.Dialog.alert("启用成功！启用" + result + "条数据", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("启用失败！");
        }
    }

    //禁用
    function DisablehandleResult(result) {
        if (result != -1) {
            top.Dialog.alert("禁用成功！禁用" + result + "条数据", null, null, null, 1);
            grid.loadData();
        } else {
            top.Dialog.alert("禁用失败！");
        }
    }
    //启用
    function onEnable(rowid, rowidx) {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选中要启用的记录!");
            return;
        }
        $.post("/WarehouseDefine/onEnable",
            //获取所有选中行
            getSelectId(grid),
            function(result) {
                EnablehandleResult(result.status);
            },
            "json");
    }
    //禁用
    function onDisable(rowid, rowidx) {
        var rows = grid.getSelectedRows();
        var rowsLength = rows.length;

        if (rowsLength == 0) {
            top.Dialog.alert("请选中要禁用的记录!");
            return;
        }
        top.Dialog.confirm("确定要禁用吗？", function() {
            $.post("/WarehouseDefine/onDisable",
                //获取所有选中行
                getSelectId(grid),
                function(result) {
                    DisablehandleResult(result.status);
                },
                "json");
        });
    }


    //刷新表格 表单提交的回调
    function afterFormSubmit() {
        grid.loadData();
    }

    //刷新表格数据并重置排序和页数
    function refresh(isUpdate) {
        if (!isUpdate) {
            //重置排序
            grid.options.sortName = 'warehouseId';
            grid.options.sortOrder = "desc";
            //页号重置为1
            grid.setNewPage(1);
        }
        grid.loadData();
    }

</script>	